package sctu.edu.java.year2016.team07.nieying.day20160607.chapter12_2;

import sctu.edu.java.year2016.team01.renxinpeng.day20160610.chapter12_1.Read;
import sctu.edu.java.year2016.team02.wanggaowen.Pra.Fil;
import sctu.edu.java.year2016.team04.Liliang.day20160529.chapter8_2.Out;

import java.io.*;

/**
 * Created by Administrator on 2016/6/13 0013.
 */

/**
 * 编写程序，使用字符输入，输出流读取文件，将
 * 一段文字加密后，然后再读取，并将加密前与加密后的文件输出
 */
public class EncryptFile {
       public void befor()throws Exception {
           File file = new File("E:\\word.txt");
           try {
               FileOutputStream Out = new FileOutputStream(file);
               byte name[] = "我是大学生".getBytes();
               System.out.println("未加密文件");
               Out.write(name);
               Out.close();
           } catch (Exception e) {
               e.printStackTrace();
           }
           try {
               FileInputStream In=new FileInputStream(file);
               byte name[]=new byte[1024];
               int len=In.read(name);
               System.out.println("内容是："+new String(name,0,len));
               In.close();
           }catch (Exception e){
               e.printStackTrace();
           }
       }
        public void after()throws Exception{
        File file=new File("E:\\word.txt");
            Reader in=new FileReader(file);
            char[] a=new char[50];
            int Len=1;
            StringBuffer b=new StringBuffer();
            try{
                while ((Len!=1)){
                    b.append(new String(a,0,Len));
                }
                in.close();
                System.out.println("加密后的文件");
                System.out.println("内容为：" + a);

            }catch (Exception e){
                e.printStackTrace();
            }
   }
 public static void main(String[] args)throws Exception{
     EncryptFile c=new EncryptFile();
     try{
         c.befor();
     }catch (Exception e){
         e.printStackTrace();

     }
     c.after();
 }

       }

